<?php
    session_start();
	include("conf/conf.php");
    $dbConf = new AAConf();
    $databaseURL = $dbConf->get_databaseURL();
    $databaseUName = $dbConf->get_databaseUName();
    $databasePWord = $dbConf->get_databasePWord();
    $databaseName = $dbConf->get_databaseName();
    $connection = mysql_connect($databaseURL,$databaseUName,$databasePWord );
    if (!$connection){
            die('Error al conectarse a la base de datos:'. mysql_error());
    }
    $db = mysql_select_db($databaseName,$connection);
	
	$historico=$_REQUEST['Historico'];
	$activo=$_REQUEST['Activo'];
	
	if (!empty($_POST['Reordenar'])){
		$orden=$_REQUEST['orden'];
	}else{
		$orden='NombreProyecto';
	}
	
	
	$idACambiar=$_REQUEST['identificadorAnuncio'];
		if(!empty($idACambiar)){
			$a = mysql_query("SELECT Activo FROM anuncio WHERE ID = '$idACambiar'");
			$activo = mysql_fetch_row($a);
			if($activo[0]==1){
				mysql_query("UPDATE anuncio SET Activo=0 WHERE ID = '$idACambiar';");
			}else{
				mysql_query("UPDATE anuncio SET Activo=1 WHERE ID = '$idACambiar';");
			}
			header ("Location: administrarhistorico.php");
		}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Vitamina U</title>
        <meta name="keywords" content="itinerary, list" />
        <meta name="description" content="This page provides a list of all itineraries" />
        <link href="css/default.css" rel="stylesheet" type="text/css" />

    </head>

    <body>
		<div id="wrapper">
        <?php include 'include/header.php'; ?>
            <!-- end div#header -->
            <div id="page">
                <div id="content">
                    <div id="welcome">
					<center><h1>Administrar Anuncios</h1>

					</center>
					<?php
						$result = mysql_query("SELECT NombreProyecto, ID FROM anuncio WHERE IdentificadorEncargado='$_SESSION[id]' AND Activo=1 ORDER BY $orden;;", $connection);
						IF($result){
							echo "<center><table border = '0'> \n";
							echo "<tr> \n";
							echo "<th><center><font color=#AA2808><b>Nombre</b><font></center></th> \n";
							echo "<th><center><font color=#AA2808><b>ID</b><font></center></th> \n";
							echo "</tr> \n";
							while ($row = mysql_fetch_row($result)){
								echo "<tr> \n";
								echo "<td>$row[0]</td> \n";
								echo "<td>$row[1]</td> \n";
								echo "</tr> \n";
							}
							echo "</table></center> \n";
						}
					?>
                    </div>
                    
                    <!-- end div#welcome -->			
                    <!--
					<div class="dtree">
					<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>
					<script type="text/javascript">
						d = new dTree('d');
						d.add(0,-1,'My example tree');
						d.add(1,0,'Node 1','example01.html');
						d.add(2,0,'Node 2','example01.html');
						d.add(3,1,'Node 1.1','example01.html');
						d.add(4,0,'Node 3','example01.html');
						d.add(5,3,'Node 1.1.1','example01.html');
						d.add(6,5,'Node 1.1.1.1','example01.html');
						d.add(7,0,'Node 4','example01.html');
						d.add(8,1,'Node 1.2','example01.html');
						d.add(9,0,'My Pictures','example01.html','Pictures I\'ve taken over the years','','','img/imgfolder.gif');
						d.add(10,9,'The trip to Iceland','example01.html','Pictures of Gullfoss and Geysir');
						d.add(11,9,'Mom\'s birthday','example01.html');
						d.add(12,0,'Recycle Bin','example01.html','','','img/trash.gif');
						document.write(d);
					</script>
					</div> -->	

                </div>
                <!-- end div#content -->
				
				<div id="sidebar">
					<br/><br/>
                    <center><H1>Opciones<H1></center>
					<ul>
					<li><center><H3><font size = '2'><a href='crearanuncio.php'>Crear un nuevo anuncio</a></font></H3></center></li>
					</ul>
					<ul>
					<li><center><H3><font size = '2'><a href='escogereditaranuncio.php'>Editar anuncio</a></font></H3></center></li>
					</ul>
					<ul>
					<li><H2>Reordenar anuncios</H2><br/>
						<FORM METHOD='POST' ACTION='administrarproyectodocente.php'>
							<center><SELECT NAME="orden" ID="orden">
							   <OPTION VALUE="NombreProyecto">Nombre</OPTION>
							   <OPTION VALUE="UnidadAcademica">Unidad Acad&eacute;mica</OPTION>
							   <OPTION VALUE="FechaApertura">Fecha de Apertura</OPTION>
							   <OPTION VALUE="FechaCierre">Fecha de Cierre</OPTION>
							   <OPTION VALUE="Visitas">Cantidad de Visitas</OPTION>
							</SELECT>
							<br/><br/><input type="submit" name="Reordenar" id="Reordenar" value="Reordenar" ></center>
						</FORM>
					</li>
					</ul>
                </div>
				
                <div style="clear: both; height: 1px"></div>
            </div>
            <?php include 'include/footer.php'; ?>

        </div>
        <!-- end div#wrapper -->
    </body>
</html>